﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CardsAlbumDAL
{
    class DAL
    {
        static void Main(string[] args)
        {
            //CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
            //int id = CreateUser("Toshko1", "afrikansk1i", "Toshko b1oskov", "tofsa1@abv.bg");
            //Console.WriteLine(id);
            //User user = GetUserById(cardsAlbumModel, 2);
            //Console.WriteLine(user.FullName);
            //ModifyUser(2, "blalala", "goshko", "gosh@abv.bg");
            //DeleteUser(3);
            //CreateCategory("OurCategory", 1, DateTime.Now, "The Second Category");
            //Category cat = GetCategoryById(cardsAlbumModel,1);
            //Console.WriteLine(cat.Description);
            //ModifyCategory(2, "ModifiedSecondCategory", "Desc2");
            ////DeleteCategory(2);
            //int id = CreateCard(1, DateTime.Now, "This is our first card", new List<int> { 1 });
            //Console.WriteLine(id);
            //ModifyCard(6, "new card description");
            //DeleteCard(6);
            //AddCategoryToCard(7, 1);
            //DeleteCategoryFromCard(7, 1);
            //AddComment("first comment ever", "theres the content", 1, 7);
            //Console.WriteLine(GetCommentById(cardsAlbumModel, 1).Contents); 
            //DeleteComment(1);
            //ModifyComment(2, "its 2");
        }
        //static int CreateUser(string username, string password, string fullName, string email)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    User newUser = new User()
        //    {
        //        Username = username,
        //        Password = password,
        //        FullName = fullName,
        //        Email = email
        //    };
        //    cardsAlbumModel.Add(newUser);
        //    cardsAlbumModel.SaveChanges();
        //    int id = newUser.Id;
        //    return id;
        //}

        //static User GetUserById(CardsAlbumModel cardsAlbumModel, int userId)
        //{
        //    User found = cardsAlbumModel.Users.FirstOrDefault(x => x.Id == userId);
        //    return found;
        //}

        //static void ModifyUser(int userId, string password, string fullName, string email)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    User toModify = GetUserById(cardsAlbumModel, userId);
        //    toModify.Password = password;
        //    toModify.FullName = fullName;
        //    toModify.Email = email;
        //    cardsAlbumModel.SaveChanges();
        //}

        //static void DeleteUser(int userId)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    User userToDelete = GetUserById(cardsAlbumModel, userId);
        //    cardsAlbumModel.Delete(userToDelete);
        //    cardsAlbumModel.SaveChanges();
        //}

        //static int CreateCategory(string name, int authorId, DateTime publishDate, string description)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Category newCategory = new Category()
        //    {
        //        Name = name,
        //        AuthorId = authorId,
        //        PublishDate = publishDate,
        //        Description = description
        //    };
        //    cardsAlbumModel.Add(newCategory);
        //    cardsAlbumModel.SaveChanges();
        //    int id = newCategory.Id;
        //    return id;
        //}

        //static Category GetCategoryById(CardsAlbumModel cardsAlbumModel, int categoryId)
        //{
        //    Category found = cardsAlbumModel.Categories.FirstOrDefault(x => x.Id == categoryId);
        //    return found;
        //}

        //static void ModifyCategory(int categoryId, string name, string description)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Category toModify = GetCategoryById(cardsAlbumModel, categoryId);
        //    toModify.Name = name;
        //    toModify.Description = description;
        //    cardsAlbumModel.SaveChanges();
        //}

        //static void DeleteCategory(int categoryId)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Category categoryToDelete = GetCategoryById(cardsAlbumModel, categoryId);
        //    cardsAlbumModel.Delete(categoryToDelete);
        //    cardsAlbumModel.SaveChanges();
        //}

        //static int CreateCard(int uploaderId, DateTime uploadDate, string description, List<int> categoriesId)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Card newCard = new Card()
        //    {
        //        UploaderId = uploaderId,
        //        UploadDate = uploadDate,
        //        Description = description
        //    };
        //    cardsAlbumModel.Add(newCard);
        //    cardsAlbumModel.SaveChanges();
        //    int id = newCard.Id;

        //    foreach (var categoryId in categoriesId)
        //    {
        //        CardsCategory cardCat = new CardsCategory()
        //        {
        //            CardId = id,
        //            CategoryId = categoryId
        //        };
        //        cardsAlbumModel.Add(cardCat);
        //    }
        //    cardsAlbumModel.SaveChanges();
        //    return id;
        //}

        //static Card GetCardById(CardsAlbumModel cardsAlbumModel, int cardId)
        //{
        //    Card found = cardsAlbumModel.Cards.FirstOrDefault(x => x.Id == cardId);
        //    return found;
        //}

        //static void ModifyCard(int cardId, string description)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Card toModify = GetCardById(cardsAlbumModel, cardId);
        //    toModify.Description = description;
        //    cardsAlbumModel.SaveChanges();
        //}

        //static void DeleteCard(int cardId)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Card cardToDelete = GetCardById(cardsAlbumModel, cardId);
        //    cardsAlbumModel.Delete(cardToDelete);
        //    cardsAlbumModel.SaveChanges();
        //}

        //static void AddCategoryToCard(int cardId, int categoryId)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    CardsCategory cardCategory = new CardsCategory();
        //    cardCategory.CardId = cardId;
        //    cardCategory.CategoryId = categoryId;
        //    cardsAlbumModel.Add(cardCategory);
        //    cardsAlbumModel.SaveChanges();
        //}

        //static void DeleteCategoryFromCard(int cardId, int categoryId)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    CardsCategory cardsCategory = cardsAlbumModel.CardsCategories.FirstOrDefault(x => x.CategoryId == categoryId &&
        //        x.CardId == cardId);
        //    cardsAlbumModel.Delete(cardsCategory);
        //    cardsAlbumModel.SaveChanges();
        //}

        //static int AddComment(string title, string contents, int userId, int cardId)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Comment newComment = new Comment()
        //    {
        //        Title = title,
        //        Contents = contents,
        //        UserId = userId,
        //        CardId = cardId
        //    };
        //    cardsAlbumModel.Add(newComment);
        //    cardsAlbumModel.SaveChanges();
        //    int result = newComment.Id;
        //    return result;
        //}

        //static Comment GetCommentById(CardsAlbumModel cardsAlbumModel, int commentId)
        //{
        //    Comment result = cardsAlbumModel.Comments.FirstOrDefault(x => x.Id == commentId);
        //    return result;
        //}

        //static void DeleteComment(int commentId)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Comment toDelete = GetCommentById(cardsAlbumModel, commentId);
        //    cardsAlbumModel.Delete(toDelete);
        //    cardsAlbumModel.SaveChanges();
        //}

        //static void ModifyComment(int commentId, string newContent)
        //{
        //    CardsAlbumModel cardsAlbumModel = new CardsAlbumModel();
        //    Comment toModify = GetCommentById(cardsAlbumModel, commentId);
        //    toModify.Contents = newContent;
        //    cardsAlbumModel.SaveChanges();
        //}
    }
}
